package com.example.remsad;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;

public class Helper {

	public String GetTextViewToString(View view) {
		TextView buffer = (TextView) view;
		String text = buffer.getText().toString();
		return text;
	}

	public String GetSpinnerView(View view) {
		Spinner spinner = (Spinner) view;
		String text = spinner.getSelectedItem().toString();
		return text;
	}

}

class DatePickerFragment extends DialogFragment implements
		DatePickerDialog.OnDateSetListener {

	private TextView input;

	public void setInputId(TextView input) {
		this.input = input;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		// final Calendar c = Calendar.getInstance();
		int year = 1990;// c.get(Calendar.YEAR);
		int month = 6;// c.get(Calendar.MONTH);
		int day = 1;// c.get(Calendar.DAY_OF_MONTH);

		// Create a new instance of DatePickerDialog and return it
		return new DatePickerDialog(getActivity(), this, year, month, day);
	}

	public void onDateSet(DatePicker view, int year, int month, int day) {
		this.input.setText(Integer.toString(day) + "/"
				+ Integer.toString(month+1) + "/" + Integer.toString(year));
	}

}

class TimePickerFragment extends DialogFragment implements
		TimePickerDialog.OnTimeSetListener {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current time as the default values for the picker
		final Calendar c = Calendar.getInstance();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);

		// Create a new instance of TimePickerDialog and return it
		return new TimePickerDialog(getActivity(), this, hour, minute,
				DateFormat.is24HourFormat(getActivity()));
	}

	public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
		// Do something with the time chosen by the user
	}
}